#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
int main()
{
	FILE* pf;
	pf = fopen("my_file.txt", "w");
	if (pf != NULL)
	{
		printf("pf fopen success\n");
		fputc('a', pf);
		fputs(" fopen file\n", pf);
		fputs("next file\n", pf);
		fclose(pf);
	}

	FILE* pfile1 = fopen("my_file.txt", "a");
	if (pfile1 != NULL)
	{
		printf("pfile1 fopen success\n");
		fputs("pfile1 fputs test\n", pfile1);
		fprintf(pfile1, "pfile1 fprintf test\n");
		fclose(pfile1);
	}
	
	//拷贝文件
	FILE* pfin = fopen("my_file.txt", "r");
	if (pfin == NULL)
	{
		perror("pfin fopen");
		exit(1);
	}
	else
		printf("pfin fopen success\n");

	FILE* pfout = fopen("my_file_copy.txt", "w");
	if (pfout == NULL)
	{
		perror("pfout fopen");
		exit(1);
	}
	else
		printf("pfout fopen success\n");

	int ch = 0;
	while ((ch = fgetc(pfin)) != EOF)
	{
		fputc(ch, pfout);
	}

	fclose(pfin);
	pfin = NULL;

	fclose(pfout);
	pfout = NULL;
	return 0;
}